go to previous page   go to home page   go to next page

Answer:

Many; the exact number depends on how fast the knob is moved.


getValueIsAdjusting()

In the previous program, the number in the text box changes continuously as the knob is moved. Usually you want this. But sometimes the change listener calls code that does a great deal of work. There may be hundreds of change events, and responding to each one would slow down the program. The following method can help avoid unnecessary work:

boolean getValueIsAdjusting()

This method returns true while the knob is still moving.


QUESTION 13:

Fill in the blank so that the following fragment changes the text field only after the knob has stopped.

source = (JSlider)evt.getSource() ;

if ( source. )  // consider the boolean return value
{
  if ( source.getName()().equals("sliderA") )
    textA.setText( source.getValue() + " " );
  if ( source.getName()().equals("sliderB") )
    textB.setText( source.getValue() + " " );
    
  // do an enormous amount of work here, using the new values
  . . . .
}